package com.shisfish.english.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.shisfish.core.common.GlobalVariable;
import com.shisfish.core.dto.ResultDto;
import com.shisfish.english.model.Note;
import com.shisfish.english.service.INoteService;
import com.shisfish.english.transform.INoteTransform;

@Service(value = "noteService")
public class NoteServiceImpl implements INoteService {

	@Resource
	INoteTransform noteTransform;
	
	@Override
	public ResultDto<List<Note>> selectByParams(String content, Long category) {
		List<Note> noteList = noteTransform.selectByParams(content, category);
		if (noteList == null || noteList.size() == 0) 
			noteList = new ArrayList<>();
		return new ResultDto<List<Note>>(noteList);
	}

	@Override
	public ResultDto<List<Note>> pageByParams(Integer pageIndex, Integer pageSize, String content, Long category) {
		int index = pageIndex == null ? GlobalVariable.PAGEINDEX : pageIndex;
		int size = pageSize == null ? GlobalVariable.PAGESIZE : pageSize;
		int pageBeginIndex = (index - 1) * pageSize;
		List<Note> noteList = noteTransform.pageByParams(pageBeginIndex, size, content, category);
		if (noteList == null || noteList.size() == 0) 
			noteList = new ArrayList<>();
		return new ResultDto<List<Note>>(noteList);
	}

}
